home *** CD-ROM | disk | FTP | other *** search
- /* ANTLRToken.h
- *
- * SOFTWARE RIGHTS
- *
- * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
- * Set (PCCTS) -- PCCTS is in the public domain. An individual or
- * company may do whatever they wish with source code distributed with
- * PCCTS or the code generated by PCCTS, including the incorporation of
- * PCCTS, or its output, into commerical software.
- *
- * We encourage users to develop software with PCCTS. However, we do ask
- * that credit is given to us for developing PCCTS. By "credit",
- * we mean that if you incorporate our source code into one of your
- * programs (commercial product, research project, or otherwise) that you
- * acknowledge this fact somewhere in the documentation, research report,
- * etc... If you like PCCTS and have developed a nice tool with the
- * output, please mention that you developed it using PCCTS. In
- * addition, we ask that this header remain intact in our source code.
- * As long as these guidelines are kept, we expect to continue enhancing
- * this system and expect to make other tools available as they are
- * completed.
- *
- * ANTLR 1.31
- * Terence Parr
- * Parr Research Corporation
- * with Purdue University and AHPCRC, University of Minnesota
- * 1989-1995
- */
-
- #ifndef ATOKEN_H_GATE
- #define ATOKEN_H_GATE
-
- #include <string.h>
-
- #ifndef ANTLRCommonTokenTEXTSIZE
- #define ANTLRCommonTokenTEXTSIZE 100
- #endif
-
- /* must define what a char looks like; can make this a class too */
- typedef char ANTLRChar;
-
- class ANTLRAbstractToken {
- };
-
- // If the user subclasses this one, then they must do their own syn()
- // routine and FAIL() routine.
- class ANTLRLightweightToken : public ANTLRAbstractToken {
- protected:
- TokenType _type;
- public:
- TokenType getType() { return _type; }
- void setType(TokenType t) { _type = t; }
- };
-
- // What does an ANTLR Token look like?
- // This has virtual functions so that minimum token
- // size >= sizeof('int') + sizeof(vtbl pointer).
- // If you want a totally light weight token and can make your own scanner
- // define ANTLRToken by itself without subclassing ANTLRTokenBase; or, you
- // can subclass the lightweight token above.
- class ANTLRTokenBase : public ANTLRLightweightToken {
- public:
- /* Define to satisfy ANTLR error mechanism */
- virtual int line() { return 0; }
- virtual void setLine(int line) { ; }
- virtual ANTLRChar *getText() { return (ANTLRChar *)""; }
- virtual void setText(ANTLRChar *) {;}
- virtual ANTLRLightweightToken *makeToken(TokenType tt, ANTLRChar *txt, int line)
- {
- ANTLRTokenBase *t = new ANTLRTokenBase;
- t->setType(tt); t->setText(txt); t->setLine(line);
- return t;
- }
- };
-
- // if you are using DLG, your token def must derive from this class
- // min Token size is sizeof(TokenType) + space for virtual function table.
- class DLGBasedToken : public ANTLRTokenBase {
- int _line;
- public:
- int line() { return _line; }
- void setLine(int line) { _line = line; }
- DLGBasedToken(TokenType t) { setType(t); }
- DLGBasedToken() {;}
- virtual void setText(ANTLRChar *s) = 0;
- virtual ANTLRChar *getText() = 0;
- virtual ANTLRLightweightToken *makeToken(TokenType tt, ANTLRChar *txt, int line) = 0;
- };
-
- class ANTLRCommonToken : public DLGBasedToken {
- protected:
- ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1];
- public:
- ANTLRCommonToken(TokenType t, ANTLRChar *s) : DLGBasedToken(t)
- { setText(s); }
- ANTLRCommonToken() {;}
- ANTLRChar *getText() { return _text; }
- void setText(ANTLRChar *s) { strncpy((char *)_text, (char *)s, ANTLRCommonTokenTEXTSIZE); }
- virtual ANTLRLightweightToken *makeToken(TokenType tt, ANTLRChar *txt, int line)
- {
- ANTLRCommonToken *t = new ANTLRCommonToken;
- t->setType(tt); t->setText(txt); t->setLine(line);
- return t;
- }
- };
-
- typedef ANTLRCommonToken ANTLRCommonBacktrackingToken;
-
- #endif
-